﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;
using NS.Model;
using Shops = NS.BLL.Shops;

namespace Admin.Admin.ShopMan
{
    public partial class ShopModel : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            IsLogin();

            if (!IsPostBack)
            {
                if (Request.QueryString["ShopID"] != null)
                {
                    int shopID = Convert.ToInt32(Request.QueryString["ShopID"]);
                    ShopID.Text = shopID.ToString();
                    Bind(shopID);
                }
            }
        }

        protected void Bind(int shopID)
        {
            NS.Model.Shops shopModel = new NS.BLL.Shops().GetModel(shopID);
            if (shopModel != null)
            {
                ShopName.Text = shopModel.ShopName;
                ShopSlogan.Text = shopModel.ShopSlogan;
                ShopIntro.Text = shopModel.ShopIntro;
                ShopNotice.Text = shopModel.ShopNotice;
                Account.Text = shopModel.ShopAccount;
                Password.Text = shopModel.Password;
                QQ.Text = shopModel.QQ;
                Age.Text = shopModel.Age.ToString();
                Location.Text = shopModel.Location;
                Height.Text = shopModel.Height.ToString();
                Weight.Text = shopModel.Weight.ToString();
                Job.Text = shopModel.Job;
                OnlineTime.Text = shopModel.OnlineTime;
                IsAvailable.SelectedValue = shopModel.IsAvailable.ToString();
            }
        }

        protected void Editor_Click(object sender, EventArgs e)
        {
            NS.BLL.Shops shopBll = new Shops();
            NS.Model.Shops shopModel = shopBll.GetModel(Convert.ToInt32(ShopID.Text));
            shopModel.ShopName = ShopName.Text;
            shopModel.ShopSlogan = ShopSlogan.Text;
            shopModel.ShopIntro = ShopIntro.Text;
            shopModel.ShopNotice = ShopNotice.Text;
            shopModel.ShopAccount = Account.Text;
            shopModel.Password = Password.Text;
            shopModel.QQ = QQ.Text;
            shopModel.Age = Convert.ToInt32(Age.Text);
            shopModel.Location = Location.Text;
            shopModel.Height = Convert.ToInt32(Height.Text);
            shopModel.Weight = Convert.ToInt32(Weight.Text);
            shopModel.Job = Job.Text;
            shopModel.OnlineTime = OnlineTime.Text;
            shopModel.LastUpdateTime = DateTime.Now;
            shopModel.IsAvailable = Convert.ToInt32(IsAvailable.SelectedValue);
            shopBll.Update(shopModel);

            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "修改成功", "ShopList.aspx");
        }

        protected void Delete_Click(object sender, EventArgs e)
        {
            NS.BLL.Shops shopBll = new NS.BLL.Shops();
            int shopID = int.Parse(this.ShopID.Text);
            if (shopBll.Delete(shopID))
            {
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "删除成功", "ShopList.aspx");
            }
            else
            {
                Maticsoft.Common.MessageBox.Show(this, "删除失败");
            }
        }
    }
}